package com.nny.alarm.alert;

import android.content.Context;
import android.view.GestureDetector;
import android.view.MotionEvent;

public class NNYGesture extends GestureDetector.SimpleOnGestureListener
{
	GestureDetector mGestureDetector;
	OnActionListener mOnActionListener;
	
	public NNYGesture(Context ctx)
	{
		mGestureDetector = new GestureDetector(this);
	}
	
	public void setOnActionListener(OnActionListener l)
	{
		mOnActionListener = l;
	}
	
	public boolean onTouchEvent(MotionEvent ev)
	{
		return mGestureDetector.onTouchEvent(ev);
	}
	
	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY)
	{
		final int dx = (int)Math.abs(e1.getX() - e2.getX());
		final int dy = (int)Math.abs(e1.getY() - e2.getY());
		if((dx > 300 || dy > 300) && mOnActionListener != null)
		{
			return mOnActionListener.onAction(OnActionListener.ACTION_SNOOZE);
		}			
		return false;
	}
}
